using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using LESLogica;

public partial class editarTarefa : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.TabContainer1.ActiveTabIndex = 1;
        if ((Session["tarefaParaEditar"] != null) && ((bool)(Session["tarefaParaEditar"])))
        {
            Session["tarefaParaEditar"] = null;
            int idTarefa = (int)(Session["idTarefa"]);
            FacadeService fachada = new FacadeService();

            STarefa tarefaEditada = fachada.GetTarefa(idTarefa);

            this.TextBoxDescricao.Text = tarefaEditada.descricao;
            this.TextBoxResponsavel.Text = tarefaEditada.responsavel;
            this.TextBoxDiaData.Text = tarefaEditada.data.Day.ToString();
            this.TextBoxMesData.Text = tarefaEditada.data.Month.ToString();
            this.TextBoxAnoData.Text = tarefaEditada.data.Year.ToString();
            this.TextBoxTempoDuracao.Text = tarefaEditada.duracao.ToString();
            this.TextBoxNotas.Text = tarefaEditada.notasAdicionais;
        }
    }
    protected void ButtonSalvarAlteracoes_Click(object sender, EventArgs e)
    {
        this.LabelErroData.Text = "";
        if (!ValidadorData.validarData(this.TextBoxDiaData.Text, this.TextBoxMesData.Text, this.TextBoxAnoData.Text))
        {
            this.LabelErroData.Text = "Erro na data (DD/MM/AAAA)";
        }
        else
        {
            FacadeService service = new FacadeService();

            int idTarefa = (int)(Session["idTarefa"]);

            DateTime data = new DateTime(System.Convert.ToInt32(this.TextBoxAnoData.Text),
                    System.Convert.ToInt32(this.TextBoxMesData.Text), System.Convert.ToInt32(this.TextBoxDiaData.Text));

            service.UpdateTarefa(idTarefa, this.TextBoxDescricao.Text, data,
                System.Convert.ToInt32(this.TextBoxTempoDuracao.Text), this.TextBoxResponsavel.Text,
                this.TextBoxNotas.Text);
            this.LabelConfirmacao.Text = "Tarefa atualizada com sucesso.";
        }
    }
}
